<?
require_once('../lib/Config.php');
require_once('../lib/DB.gear.php');
require_once('../lib/lib.gear.php');
require_once('../lib/lib.garden.php');
require_once('../lib/oauth.class.php');
require_once('../lib/people.class.php');
require_once('../lib/signup.class.php');

if(isset($_POST['g_key_din39s03j23ogn']) && $_POST['g_key_din39s03j23ogn'] == G_KEY)
{
    $user_id       = $_POST['user_id'];
    $user_name     = $_POST['user_name'];
    $type          = $_POST['type'];
    $profile_image = $_POST['profile_image'];

    $profile_image_file_name = getFileName($profile_image);
    $data = file_get_contents($profile_image);
    file_put_contents('../profile_image/'.$profile_image_file_name, $data);

    $signup = new SIGNUP;

    if($signup->load_user($user_id, $type))
    {
        $signup->login($signup->get_user_id());
        $data_signup = 'login';
    }
    else
    {
        $signup->register_user($user_id, $user_name, $profile_image_file_name, $type);
    	$signup->load_user($user_id, $type);
    	$signup->login($signup->get_user_id());
        $data_signup = 'signup';
    }


    $user_id       = $signup->get_user_id();
    $mixi_id       = $signup->get_mixi_id();
    $facebook_id   = $signup->get_facebook_id();
    $twitter_id    = $signup->get_twitter_id();
    $user_name     = $signup->get_user_name();
    $profile_image = $signup->get_profile_image();
    $g_session     = $signup->get_g_session();
    $expire        = $signup->get_expire();

    $data = array(
                   'user_id'        => $user_id,
                   'mixi_id'        => $mixi_id,
                   'facebook_id'    => $facebook_id,
                   'twitter_id'     => $twitter_id,
                   'user_name'      => $user_name,
                   'profile_image'  => $profile_image,
                   'g_session'      => $g_session,
                   'expire'         => $expire,
                   'status'         => $data_signup,
                  );

    $json_data = json_encode($data);

    echo $json_data;
    //preDump(json_decode($json_data));

}
else
{
    $data = array(
                   'status'  => 'error',
                  );
    $json_data = json_encode($data);
}

?>
